<template lang="">
    <div>
        <h1 style="color: red;">Count组件的求和为：{{sum}}</h1>
        <h1>人员列表</h1>
        <h2>列表中第一个人的名字：{{firstPersonName}}</h2>
        <input type="text" placeholder="请输入名字" v-model="name">
        <button @click="add">添加</button>
        <button @click="addPersonServer">添加一个人，名字来自服务器</button>
        <ul>
            <li v-for="p in personList" :key="p.id">{{p.name}}</li>
        </ul>
    </div>
</template>
<script>
    import {nanoid} from 'nanoid'
    export default {
        name:"Person",
        data(){
            return{
                name:''
            }
        },
        computed:{
            personList(){
                return this.$store.state.personeOptions.personList
            },
            sum(){
                return this.$store.state.countOptions.sum
            },
            firstPersonName(){
                return this.$store.getters["personeOptions/firstPersonName"]
            }
        },
        methods: {
            add(){
                const obj = {id:nanoid(),name:this.name};
                this.$store.commit("personeOptions/ADDPerson",obj)
                this.name=""
            },
            addWang(){
                const obj = {id:nanoid(),name:this.name};
                this.$store.dispatch("personeOptions/ADDPerson",obj)
                this.name=""
            },
            addPersonServer(){
                this.$store.dispatch("personeOptions/addPersonServer")
            }
        },
    }
</script>
<style lang="">
    
</style>